﻿using System;
using System.Collections.Generic;
using System.Text;
using Mang24k99.Model.GOLD;
using NHibernate;
using NHibernate.Expression;
using Mang24k99.Model.COMM;

namespace Mang24k99.Business.GOLD
{
    public static class BKtGoldGoldbreed
    {

        public static IList<MKtGoldGoldbreed> FindAll()
        {
            return MKtGoldGoldbreed.SelectAll();
        }

        public static MKtGoldGoldbreed Find(object ID)
        {
            return MKtGoldGoldbreed.SelectByPrimaryKey(ID);
        }

        public static IList<MKtGoldGoldbreed> FindALLByProperty(string property, object value)
        {
            return MKtGoldGoldbreed.SelectALLByProperty(property, value);
        }

        public static IList<MKtGoldGoldbreed> FindALLSliced(int firstResult, int maxResult)
        {
            DetachedCriteria criteria = null;
            return MKtGoldGoldbreed.SelectALLSliced(firstResult, maxResult, criteria);
        }
        /// <summary>
        /// 根据产品所属类别选择金品分类（过滤掉未维护产品的类别）
        /// </summary>
        /// <returns></returns>
        public static IList<MKtCommCodeList> SelectGoldTypeByBelong(int product_type)
        {
            MKtCommCodeList codelist = new MKtCommCodeList();
            MKtGoldGoldbreed goldbreed = new MKtGoldGoldbreed();
            string where = " where codelist.CODE_NO ";
            where+= "in( select goldbreed.MKtCommCodelist.CODE_NO from MKtGoldGoldbreed goldbreed ";
            where+=" where goldbreed.ProductBelong="+product_type;
            where += " and goldbreed.CloseShow=0)";
            return (IList<MKtCommCodeList>)MKtCommCodeList.SelectByWhere(where);
        }

        /// <summary>
        /// 选择金品单位
        /// </summary>
        /// <returns></returns>
        public static IList<MKtCommCodeList> SelectGoldUnit()
        {
            string where = " where codelist.MKtCommCodeType.TYPE_CODE=303 and codelist.IS_VALIDATE=1";
            return (IList<MKtCommCodeList>)MKtCommCodeList.SelectByWhere(where);
        }
        /// <summary>
        /// 选择所有金品分类
        /// </summary>
        /// <returns></returns>
        public static IList<MKtCommCodeList> SelectGoldType()
        {
            string where = " where codelist.MKtCommCodeType.TYPE_CODE=302 and codelist.IS_VALIDATE=1";
            return (IList<MKtCommCodeList>)MKtCommCodeList.SelectByWhere(where);
        }
        /// <summary>
        /// 选择金商维护的金品品种（除金章）
        /// </summary>
        /// <returns></returns>
        public static IList<MKtCommCodeList> SelectGoldTypeBySeller()
        {
            string where = " where codelist.MKtCommCodeType.TYPE_CODE=302 and codelist.IS_VALIDATE=1";
            where += " and codelist.CODE_NO<>30207";
            return (IList<MKtCommCodeList>)MKtCommCodeList.SelectByWhere(where);
        }

        /// <summary>
        /// 选择银行维护的金品品种（金条、金章）
        /// </summary>
        /// <returns></returns>
        public static IList<MKtCommCodeList> SelectGoldTypeByBank()
        {
            string where = " where codelist.MKtCommCodeType.TYPE_CODE=302 and codelist.IS_VALIDATE=1";
            where += " and (codelist.CODE_NO=30204 or codelist.CODE_NO=30207)";
            return (IList<MKtCommCodeList>)MKtCommCodeList.SelectByWhere(where);
        }
        /// <summary>
        /// 选择最大的品种编号
        /// </summary>
        /// <returns></returns>
        public static int SelectMaxNO()
        {
            return (int)MKtGoldGoldbreed.GetMaxNO();
        }
        /// <summary>
        /// 创建一条记录
        /// </summary>
        /// <param name="goldbreed"></param>
        public static void Create(MKtGoldGoldbreed goldbreed)
        {
            MKtGoldGoldbreed.Create(goldbreed);
        }
        /// <summary>
        /// 通过品种编码返回符合条件记录
        /// </summary>
        /// <param name="breedno"></param>
        public static IList<MKtGoldGoldbreed> SelectByNO(int breedno)
        {
            string where = "where goldbreed.BreedNO=" + breedno ;
            return (IList<MKtGoldGoldbreed>)MKtGoldGoldbreed.SelectByWhere(where);
        }
        /// <summary>
        /// 根据产品名称，产品大类，产品归属类别（金商or银行）
        /// </summary>
        /// <param name="breedname"></param>
        /// <param name="breedtype"></param>
        /// <param name="belong"></param>
        /// <returns></returns>
        public static IList<MKtGoldGoldbreed> SelectByName(string breedname, int breedtype,int belong)
        {
            string where = "where goldbreed.BreedName='" + breedname + "'";
                    where+=" and goldbreed.MKtCommCodelist.CODE_NO=" + breedtype;
                    where += " and goldbreed.ProductBelong=" + belong;
            return (IList<MKtGoldGoldbreed>)MKtGoldGoldbreed.SelectByWhere(where);
        }
        /// <summary>
        /// 根据产品归属类别（金商or银行）以及品种大类选择维护的产品
        /// </summary>
        /// <param name="breedtype"></param>
        /// <param name="belong"></param>
        /// <returns></returns>
        public static IList<MKtGoldGoldbreed> SelectByType(int breedtype,int belong)
        {
            MKtGoldGoldbreed goldbreed = new MKtGoldGoldbreed();
            string where = "where  goldbreed.MKtCommCodelist.CODE_NO=" + breedtype;
                    where+=" and goldbreed.ProductBelong=" + belong;
            return (IList<MKtGoldGoldbreed>)MKtGoldGoldbreed.SelectByWhere(where);
        }
        /// <summary>
        /// 根据产品归属类别（金商or银行）,品种大类和关闭标示选择维护的产品
        /// </summary>
        /// <param name="breedtype"></param>
        /// <param name="belong"></param>
        /// <param name="closeshow"></param>
        /// <returns></returns>
        public static IList<MKtGoldGoldbreed> SelectByType(int breedtype, int belong,int closeshow)
        {
            MKtGoldGoldbreed goldbreed = new MKtGoldGoldbreed();
            string where = "where  goldbreed.MKtCommCodelist.CODE_NO=" + breedtype;
            where += " and goldbreed.ProductBelong=" + belong;
            where += " and goldbreed.CloseShow="+closeshow;
            return (IList<MKtGoldGoldbreed>)MKtGoldGoldbreed.SelectByWhere(where);
        }
    }
}
